|
|
|
|
|
|
|
Listing C.22 EXECUTE.TXTRun SQL Statements with the DatabaseExecute or QueryExecute Method |
|
|
|
|
|
|
|
|
Dim OldDb AS Database, NewQry AS QueryDef
'****************************************************
'Define the SQL statement and assign it to a variable
'****************************************************
SQLstate = "UPDATE Customers SET SalesID = 'EGREEN'"
SQLstate = SQLstate + " WHERE SalesID='JBURNS'"
'*****************************************
'Use the database execute to run the query
'*****************************************
OldDb.Execute SQLstate
'****************************************
'Create a QueryDef from the SQL statement
'****************************************
Set NewQry = OldDb.CreateQueryDef("Change Sales", SQLstate)
'**************************************
'Use the query execute to run the query
'**************************************
NewQry.Execute
'****************************************************
'Run the named query with the database execute method
'****************************************************
OldDb.Execute "Change Sales" |
|
|
|
|
|
|
|
|
Creating a QueryDef lets you name your query and store it in the database with your tables. You can create either an action query or a retrieval query (one that uses the SELECT statement). After the query is created, you can call it by name for execution (shown in a listing in the previous section "Executing an Action Query") or for creation of a dynaset (as described in the following section). Listing C.22 showed how to create a QueryDef called Change Sales that is used to update the salesperson ID for a group of customers. |
|
|
|
|
|
|
|
|
Creating Dynasets and Snapshots |
|
|
|
|
|
|
|
|
To use the SELECT statement to retrieve records and store them in a dynaset or snapshot, you must use the SELECT statement in conjunction with the OpenRecordset method. Using the OpenRecordset method, you specify the type of recordset with the options parameter. With this method, you either can use the SELECT statement directly or use the name of a retrieval query that you have previously defined. Listing C.23 shows these two methods of retrieving records. |
|
|
|
|
|